package com.neusoft.ysu.his.service.impl;

import com.neusoft.ysu.his.entity.CommonResult;
import com.neusoft.ysu.his.entity.Dept;
import com.neusoft.ysu.his.mapper.DeptMapper;
import com.neusoft.ysu.his.service.IDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 作者：赵子鉴
 * @since 2023-08-25
 */
@Service
public class DeptServiceImpl  implements IDeptService {
    @Autowired
    DeptMapper deptMapper;

    @Override
    public CommonResult findAll() {
        List<Dept> d= deptMapper.selectList(null);
        System.out.println(d);
        return new CommonResult<>(deptMapper.selectList(null));
    }

    @Override
    public CommonResult findByCode(int deptCode) {
        return new CommonResult<>(deptMapper.findByCode(deptCode));
    }

    @Override
    public CommonResult insert(Dept dept) {

        int i=deptMapper.insert(dept);
        System.out.println(dept.getId());
        dept.setDeptCode(Integer.toString(dept.getId()));
        deptMapper.updateById(dept);
        return new CommonResult<>(i);
    }

    @Override
    public CommonResult updateByCode(Dept dept) {
        System.out.println("数据库更新："+dept);
        return new CommonResult<>(deptMapper.updateByCode(dept));
    }

    @Override
    public CommonResult deleteByDeptCode(Dept dept) {

        return new CommonResult<>(deptMapper.deleteByregnum(dept));
    }

}
